import time

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.extensions.android.gsm import GsmCallActions
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions

from utils import *


class TestBrowser:
    def setup(self):
        desired_caps = {
            'platformName': 'Android',
            'platformVersion': '6.0',
            'deviceName': '192.168.57.101:5555',
            'resetKeyBoard': True,
            'unicodeKeyboard': True,
            'noReset': True,
            'automationName': 'Uiautomator2',
            # "browser": "Browser",
            "appPackage": "cn.emoney.emstock",
            "appActivity": "cn.emoney.acg.act.main.MainAct",
            # "chromedriverExecutable": "/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver77",
            "chromedriverExecutableDir": "/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver77",
            "avd": "192.168.57.101:5555"

        }

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        self.driver.implicitly_wait(5)

    def teardown(self):
        # self.driver.quit()
        pass

    def test_mobile(self):
        head_img = By.ID, 'cn.emoney.emstock:id/headIV'
        activity_btn = By.XPATH, '//*[@text="活动中心"]'
        get_element(self.driver, head_img).click()
        time.sleep(5)
        self.driver.make_gsm_call('18800000001', GsmCallActions.CALL)
        get_element(self.driver, activity_btn).click()
        time.sleep(5)
        self.driver.send_sms('18800000002', '短信内容')
        time.sleep(10)
        self.driver.set_network_connection()